<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org/">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>用户管理</title>
<link rel="stylesheet" type="text/css" href="/css/bootstrap.css" th:href="@{/css/bootstrap.css}" />
<link rel="stylesheet" type="text/css" href="/css/back-index.css"  th:href="@{/css/back-index.css}"/>
<link rel="stylesheet" href="/layui/css/layui.css" th:href="@{/layui/css/layui.css}" media="all">
<script src="/js/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/bootstrap-paginator.js"></script>
<script src="/js/bootstrap-mypaginator.js"></script>
<script src="/layui/layui.js"></script>
<script type="text/javascript" charset="utf-8">
	$(function() {
		$(".doModify").on("click", function() {
			$(".modal-title").html("用户修改");
			$("#myModal").modal("show");
		});
		$(".updateOne").on("click", function() {
			$("#myModal").modal("hide");
		});

		// 显示隐藏查询列表
		$('#show-user-search').click(function() {
			$('#show-user-search').hide();
			$('#upp-user-search').show();
			$('.showusersearch').slideDown(500);
		});
		$('#upp-user-search').click(function() {
			$('#show-user-search').show();
			$('#upp-user-search').hide();
			$('.showusersearch').slideUp(500);
		});

		let options={
			bootstrapMajorVersion:3,
			// currentPage:"${session.pageUsers.pageNum==0?1:session.pageUsers.pageNum}",
			currentPage:[[${pageUsers.pageNum}]]==0?1:[[${pageUsers.pageNum}]],
			// totalPages:"${pageUsers.pages==0?1:pageUsers.pages}",
			totalPages:[[${pageUsers.pages}]]==0?1:[[${pageUsers.pages}]],
			pageSize:[[${pageUsers.pageSize}]],
			alignment: "center",
			pagination:true,
			pageUrl:function (type,page,current) {
				return "/manager/showUsers?pageNo="+page;
			}
		}
		$("#myPages").bootstrapPaginator(options);

	});

$(function () {

	$("#doSearch").off().on('click',function () {
		$("#showList").empty();
		$("#showList").load("/manager/searchUsers",{"loginName":$("#user-name").val(),"nickname":$("#user-nickname").val(),
					"email":$("#user-email").val(),"role":$("#role-name").val(),
					"createDate":$("#createDate").val(),"createDate2":$("#createDate2").val(),
					"signDate":$("#signDate").val(),"signDate2":$("#signDate2").val()});
		$("#myPages").hide();

	})
	// $("#username").blur(function () {
	// 	if ($("#username").val()==""||$("#username").val()==null){
	// 		alert("用户名，不可以为空!")
	// 	}
	// 	if ($("#roleName").val()==""||$("#roleName").val()==null){
	// 		alert("用户名，不可以为空!")
	// 	}
	// 	if ($("#email").val()==""||$("#email").val()==null){
	// 		alert("用户名，不可以为空!")
	// 	}
	// 	if ($("#password").val()==""||$("#password").val()==null){
	// 		alert("用户名，不可以为空!")
	// 	}
    //
	// })

	$("#modify_true").click(function () {
		$.ajax({
			type:"post",
			url:"/manager/modifyUser",
			data:{"id":$("#user_id").val(),"nickname":$("#username").val(),
			"role":$("#roleName").val(),"email":$("#email").val(),"password":$("#password").val()},
			dataType:"json",
			success:function (result) {
				alert(result)
			}
		});

	})
})

	layui.use('laydate',function () {
		let laydate = layui.laydate;
		let laydate2 = layui.laydate;
		let laydate3 = layui.laydate;
		let laydate4 = layui.laydate;
		laydate.render({
			elem: '#createDate'
			,type: 'datetime'
			 //或 range: '~' 来自定义分割字符
		});
		laydate2.render({
			elem: '#createDate2'
			,type: 'datetime'
			 //或 range: '~' 来自定义分割字符
		});
		laydate3.render({
			elem: '#signDate'
			,type: 'datetime'
			 //或 range: '~' 来自定义分割字符
		});
		laydate4.render({
			elem: '#signDate2'
			,type: 'datetime'
			 //或 range: '~' 来自定义分割字符
		});
	})

	// $("input[name='modifyStatus']").click
	function modifyStatus(userId) {
		// let a=$("input[name='modifyStatus']").attr("data-id");
		// console.log("========="+a)
		$.ajax({
			type:"post",
			url:"/manager/modifyStatus",
			data:{"userId":userId},
			dataType:"json",
			success:function (result) {
				if (result.status=="1"){
					location.href="/manager/showUsers?pageNo=1";
				}
				else {

					alert(result.message);
				}
			}
		});
	}

	function selectUser(id) {
		$.ajax({
			type:"post",
			url:"/manager/selectUser",
			data:{"id":id},
			success:function (result) {
				$("#user_id").val(result.id);
				$("#username").val(result.nickname);
				$("#roleName").val(result.role);
				$("#email").val(result.email);
				$("#password").val(result.password);

			}

		})
	}
</script>

</head>

<body>
	<div class="panel panel-default" id="userInfo">
		<div class="panel-heading">
			<h3 class="panel-title">用户管理</h3>
		</div>
		<div>
			<input type="button" value="查询" class=" btn btn-success" id="doSearch"  style="margin: 5px 5px 5px 15px;" />
			<input type="button" class="btn btn-primary" id="show-user-search" value="展开搜索" />
			<input type="button" value="收起搜索" class="btn btn-primary" id="upp-user-search" style="display: none;" />
		</div>

		<div class="panel-body">
			<div class="showusersearch" style="display: none;">
<!--				<form class="form-horizontal">-->
					<div class="form-group">
						<div class="form-group col-xs-6">
							<label for="user-name" class="col-xs-3 control-label">登录名：</label>
							<div class="col-xs-8">
								<input type="text" class="form-control" id="user-name" placeholder="请输入登录名" />
							</div>
						</div>
						<div class="form-group col-xs-6">
							<label for="user-nickname" class="col-xs-3 control-label">昵称：</label>
							<div class="col-xs-8">
								<input type="text" class="form-control" id="user-nickname"
									   placeholder="请输入昵称" />
							</div>
						</div>
					</div>
					<div class="form-group">
						<div class="form-group col-xs-6">
							<label for="user-email" class="col-xs-3 control-label">邮箱：</label>
							<div class="col-xs-8">
								<input type="text" class="form-control" id="user-email"
									   placeholder="请输入邮箱" />
							</div>
						</div>
						<div class="form-group col-xs-6">
							<label for="role-name" class="col-xs-3 control-label">角色：</label>
							<div class="col-xs-8">
								<select class="form-control" id="role-name" name="role-name">
<!--									<option value="-1">全部</option>-->
									<option value="普通用户">普通用户</option>
									<option value="会员">会员</option>
								</select>
							</div>
						</div>
					</div>
					<div class="form-group">
						<div class="form-group col-xs-6">
							<label class="col-xs-3 control-label">开始日期：</label>
							<div class="col-xs-8">
								<input type="text" class="form-control" id="createDate"
									   placeholder="请输入创建开始时间:2017-10-10" />
							</div>
						</div>
						<div class="form-group col-xs-6">
							<label class="col-xs-3 control-label">结束日期：</label>
							<div class="col-xs-8">
								<input type="text" class="form-control" id="createDate2"
									   placeholder="请输入创建结束时间:2017-10-12" />
							</div>
						</div>
					</div>
					<div class="form-group">
						<div class="form-group col-xs-6">
							<label class="col-xs-3 control-label">开始日期：</label>
							<div class="col-xs-8">
								<input type="text" class="form-control" id="signDate"
									   placeholder="请输入登录开始时间:2017-10-10" />
							</div>
						</div>
						<div class="form-group col-xs-6">
							<label class="col-xs-3 control-label">结束日期：</label>
							<div class="col-xs-8">
								<input type="text" class="form-control" id="signDate2"
									   placeholder="请输入登录结束时间:2017-10-12" />
							</div>
						</div>
					</div>
<!--				</form>-->
			</div>

			<div class="show-list" id="showList">
				<table class="table table-bordered table-hover"
					style='text-align: center;'>
					<thead>
						<tr  class="text-danger">
							<th class="text-center">编号</th>
							<th class="text-center">登录名</th>
							<th class="text-center">角色</th>
							<th class="text-center">昵称</th>
							<th class="text-center">邮箱</th>
							<th class="text-center">创建日期</th>
							<th class="text-center">最近登录日期</th>
							<th class="text-center">操作</th>
						</tr>
					</thead>
					<tbody id="tb">
						<tr th:each="user:${pageUsers.list}">
							<td th:text="${user.id}"></td>
							<td th:text="${user.loginName}"></td>
							<td th:text="${user.role}"></td>
							<td th:text="${user.nickname}"></td>
							<td th:text="${user.email}"></td>
							<td th:text="${user.createDate}"></td>
							<td th:text="${user?.signDate}"></td>
							<td class="text-center">
								<input type="button"
								class="btn btn-warning btn-sm doModify" name="modify-btn" value="修改"
								th:onclick="|javascript:selectUser('${user.id}')|"/>

								<input name="modifyStatus" th:attr="data-id=${user.id}"
								type="button" th:class="${user.status}==-1?'btn btn-danger btn-sm':'btn btn-success btn-sm'"
								th:value="${user.status}==-1?'禁用':'启用'"
								th:onclick="|javascript:modifyStatus('${user.id}')|"/>

							</td>
						</tr>

					</tbody>
				</table>
			</div>

			<!-- 分页 -->
			<div style="text-align: center;">
				<ul id="myPages" class="pagination"></ul>
			</div>

			<div class="modal fade" tabindex="-1" id="myModal">
				<!-- 窗口声明 -->
				<div class="modal-dialog modal-lg">
					<!-- 内容声明 -->
					<div class="modal-content">
						<!-- 头部、主体、脚注 -->
						<div class="modal-header">
							<button class="close" data-dismiss="modal">&times;</button>
							<h4 class="modal-title">用户修改</h4>
						</div>
						<div class="modal-body text-center">
							<div class="row text-right">
								<label for="user_id" class="col-xs-4 control-label">编号：</label>
								<div class="col-xs-4">
									<input type="text" class="form-control" id="user_id"
										readonly="true" />
								</div>
							</div>
							<br>
							<div class="row text-right">
								<label for="username" class="col-xs-4 control-label">昵称：</label>
								<div class="col-xs-4">
									<input type="text" class="form-control" id="username" />
								</div>
							</div>
							<br>
							<div class="row text-right">
								<label for="roleName" class="col-xs-4 control-label">角色：</label>
<!--								<div class="col-xs-4">-->
<!--									<input type="text" class="form-control" id="roleName" />-->
<!--								</div>-->
								<div class="col-xs-4">
									<select class="form-control" id="roleName" >
										<option value="普通用户">普通用户</option>
										<option value="会员">会员</option>
									</select>
								</div>
							</div>
							<br>
							<div class="row text-right">
								<label for="password" class="col-xs-4 control-label">密码：</label>
								<div class="col-xs-4">
									<input type="text" class="form-control" id="password" />
								</div>
							</div>
							<br>
							<div class="row text-right">
								<label for="email" class="col-xs-4 control-label">邮箱：</label>
								<div class="col-xs-4">
									<input type="email" class="form-control" id="email" />
								</div>
							</div>
							<br>
						</div>
						<div class="modal-footer">
							<button class="btn btn-warning updateOne" id="modify_true">修改</button>
							<button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>

</html>